package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.util.result.Result;
import com.atguigu.gmall.product.model.BaseSaleAttr;
import com.atguigu.gmall.product.model.SpuInfo;
import com.atguigu.gmall.product.service.SpuManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/product")
public class SpuManageController {
    @Autowired
    private SpuManageService spuManageService;

    @ApiOperation("spu分页列表")
    @GetMapping("/{page}/{size}")
    public Result<IPage<SpuInfo>> getSpuInfoPage(@PathVariable("page")Long page, @PathVariable("size")Long size, SpuInfo spuInfo){
        IPage<SpuInfo> iPage = new Page<>(page,size);
        iPage = spuManageService.getSpuInfoPage(iPage,spuInfo);
        return Result.ok(iPage);
    }

    @ApiOperation("获取销售属性数据")
    @GetMapping("/baseSaleAttrList")
    public Result<List<BaseSaleAttr>> baseSaleAttrList(){
        List<BaseSaleAttr> list = spuManageService.BaseSaleAttr();
        return Result.ok(list);
    }

    @ApiOperation("保存商品spu信息")
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        spuManageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }
}
